/**
 * 
 */
package com.dalonedrow.engine.graph;

/**
 * @author Donald
 */
public class GraphEdge {
	/** the index of the 1st of the {@link GraphNode}s this edge connects. */
	private int	from;
	/** the index of the 2nd of the {@link GraphNode}s this edge connects. */
	private int	to;
	/**
	 * Creates a new instance of {@link GraphEdge}.
	 * @param f the index of the 1st {@link GraphNode}
	 * @param t the index of the 2nd {@link GraphNode}
	 */
	public GraphEdge(final int f, final int t) {
		from = f;
		to = t;
	}
	/**
	 * Determines if this {@link GraphEdge} connects two nodes exactly in the
	 * direction provided.
	 * @param f the node the edge is coming from
	 * @param t the node the edge is going two
	 * @return true if the {@link GraphEdge} connects two nodes exactly in the
	 *         direction provided; false otherwise
	 */
	public final boolean equalsDirected(final int f, final int t) {
		return from == f && to == t;
	}
	/**
	 * Determines if this {@link GraphEdge} connects two nodes in either
	 * direction.
	 * @param e0 the first node
	 * @param e1 the second node
	 * @return true if the {@link GraphEdge} connects two nodes in either
	 *         direction; false otherwise
	 */
	public final boolean equalsUndirected(final int e0, final int e1) {
		return from == e0 && to == e1 || from == e1 && to == e0;
	}
	/**
	 * Gets the index of the 1st {@link GraphNode}s this edge connects.
	 * @return <code>int</code>
	 */
	public final int getFrom() {
		return from;
	}
	/**
	 * Gets the index of the 2nd {@link GraphNode}s this edge connects.
	 * @return <code>int</code>
	 */
	public final int getTo() {
		return to;
	}
	/**
	 * Sets the index of the 1st {@link GraphNode} this edge connects.
	 * @param f the index to set
	 */
	public final void setFrom(final int f) {
		from = f;
	}
	/**
	 * Sets the index of the 2nd {@link GraphNode} this edge connects.
	 * @param t the index to set
	 */
	public final void setTo(final int t) {
		to = t;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("From Node ");
		sb.append(from);
		sb.append(" To Node ");
		sb.append(to);
		return sb.toString();
	}
}
